﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Hallenberg.SmartClient.Menu
{
    class MenuItemIterator : IEnumerator<MenuItem>
    {
        private List<MenuItem> m_MenuItems;
        private int m_ItemIndex;

        public MenuItemIterator(List<MenuItem> menuItems)
        {
            Debug.Assert(menuItems != null);
            if (menuItems == null)
            {
                throw new ArgumentNullException("menuItems");
            }

            m_MenuItems = menuItems;

            Reset();
        }

        public MenuItem Current
        {
            get { return m_MenuItems[m_ItemIndex]; }
        }

        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }
        
        object System.Collections.IEnumerator.Current
        {
            get { return m_MenuItems[m_ItemIndex]; }
        }

        public bool MoveNext()
        {
            for (int itemIndex = m_ItemIndex + 1; itemIndex < m_MenuItems.Count; itemIndex++)
            {
                if (m_MenuItems[itemIndex].IsVisible)
                {
                    m_ItemIndex = itemIndex;
                    return true;
                }
            }

            return false;
        }

        public void Reset()
        {
            m_ItemIndex = -1;
        }
    }
}
